package com.ebs.md.api.product;

/**
 * Revision Author:
 *  $File: //depot/MarketData/commons-md-api/MAIN/src/main/java/com/ebs/md/api/product/PairProduct.java $
 *  $Revision: #3 $
 *  $DateTime: 2012/08/28 11:09:01 $
 *  $Change: 114255 $
 *  $Author: Arik.Sher $
 */

import com.ebs.md.api.IProduct;


public class PairProduct 
implements IProduct
{
	// gened via Eclipse
	private static final long serialVersionUID = -8599082633165463258L;

	protected String  baseCcyIso;
	protected String localCcyIso;
	protected int    matchingType;

	protected String cachedShortIsoName;
	protected String cachedName;
	
	public PairProduct(String baseCcyIso, String localCcyIso, int matchingType) {
		super();
		this. baseCcyIso  =  baseCcyIso;
		this.localCcyIso  = localCcyIso;
		this.matchingType = matchingType;
		
		cachedName         = generateKey         (baseCcyIso, localCcyIso, matchingType);
		cachedShortIsoName = generateShortIsoName(baseCcyIso, localCcyIso);
	}

	public String getName() {
		return cachedName; 
	}

	public String getShortIsoName() {
		return cachedShortIsoName;
	}

	public String getBaseCcyIso() {
		return baseCcyIso;
	}

	public String getLocalCcyIso() {
		return localCcyIso;
	}
	
	public int getMatchingType() {
		return matchingType;
	}

	// generated by eclipse on base+local+matchingType
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((baseCcyIso == null) ? 0 : baseCcyIso.hashCode());
		result = prime * result
				+ ((localCcyIso == null) ? 0 : localCcyIso.hashCode());
		result = prime * result + matchingType;
		return result;
	}

	// generated by eclipse on base+local+matchingType
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PairProduct other = (PairProduct) obj;
		if (baseCcyIso == null) {
			if (other.baseCcyIso != null)
				return false;
		} else if (!baseCcyIso.equals(other.baseCcyIso))
			return false;
		if (localCcyIso == null) {
			if (other.localCcyIso != null)
				return false;
		} else if (!localCcyIso.equals(other.localCcyIso))
			return false;
		if (matchingType != other.matchingType)
			return false;
		return true;
	}

	public String toString() {
		return "PairProduct:" + getName();
	}

	public static String generateShortIsoName(String baseCcyIso, String localCcyIso) {
		return String.format("%s/%s", baseCcyIso, localCcyIso);
	}

	public static String generateKey(String baseCcyIso, String localCcyIso, int matchingType) {
		return String.format("%s/%s_%d", baseCcyIso, localCcyIso, matchingType);
	}

}
